<template>
  <div>
    <el-row> <el-breadcrumb separator="/">

      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>基础信息管理</el-breadcrumb-item>
      <el-breadcrumb-item>员工信息</el-breadcrumb-item>
    </el-breadcrumb></el-row>

<!--    添加对话框dialog-->
    <el-dialog
      title="添加员工"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
     <el-form>

       <el-form-group>
         <el-form-item label="员工编号" label-width="80px">
           <el-input v-model="staff.Snum"></el-input>
         </el-form-item>
       </el-form-group>

       <el-form-group>
         <el-form-item label="员工姓名" label-width="80px">
           <el-input v-model="staff.Sname"></el-input>
         </el-form-item>
       </el-form-group>

       <el-form-group>
         <el-form-item label="员工性别" label-width="80px">
           <el-input v-model="staff.Sgender"></el-input>
         </el-form-item>
       </el-form-group>

       <el-form-group>
         <el-form-item label="员工职位" label-width="80px">
           <el-input v-model="staff.Spos"></el-input>
         </el-form-item>
       </el-form-group>

       <el-form-group>
         <el-form-item label="员工部门" label-width="80px">
           <el-input v-model="staff.Sdpt"></el-input>
         </el-form-item>
       </el-form-group>

     </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="submitHandle">确 定</el-button>
  </span>
    </el-dialog>
<!--    添加对话框结束-->

    <el-row>
      <el-form label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="用户名" label-width="80px"><input></input></el-form-item>
          </el-col>
          <el-col :span="8"><el-form-item label="用户管理" label-width="80px"><input></input></el-form-item></el-col>
          <el-col :span="8"><el-form-item label="search"><el-button></el-button></el-form-item></el-col>
        </el-row>
      </el-form>
    </el-row>

    <!--添加工具栏-->
    <div class="toolbar">
      <el-button-group>
        <el-button @click="btnAddClick" type="primary" icon="el-icon-edit">添加</el-button>
        <el-button type="primary" icon="el-icon-share">分享</el-button>
        <el-button type="primary" icon="el-icon-delete">删除</el-button>
      </el-button-group>
    </div>
    <!--添加工具栏结束-->

<!--//表格信息-->
    <el-row>
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          prop="Snum"
          label="员工编号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="Sname"
          label="姓名"
          width="180">
        </el-table-column>
        <el-table-column
          prop="Sgender"
          label="性别">
        </el-table-column>
        <el-table-column
          prop="Spos"
          label="职位">
        </el-table-column>
          <el-table-column
            prop="Sdpt"
            label="部门">
            </el-table-column>
      </el-table>
<!--      分页效果-->
      <el-pagination
        small
        layout="prev, pager, next"
        :total="50">
      </el-pagination>
    </el-row>

  </div>
</template>

<script>
    export default {
        name: "staff",
      data() {
        return {
          tableData: [],
          dialogVisible:false,
          staff:{
            Snum:'',
            Sname:'',
            Sgender:'',
            Spos:'',
            Sdpt:''
          }
        }
      },mounted() {
          var _this=this;
          this.axios({
            url:'http://localhost:3000/staff/list',
            method:'get',
          }).then(function (res) {

            _this.tableData=res.data;
          })
      },methods:{
          btnAddClick(){
            this.dialogVisible=true;
          },
        handleClose(){
            this.dialogVisible=false;
        },
        submitHandle(){
            var _this1=this;
            this.axios({
              url: 'http://localhost:3000/staff/add',
              method:'get',
              params:{
                Snum:this.staff.Snum,
                Sname: this.staff.Sname,
                Sgender: this.staff.Sgender,
                Spos: this.staff.Spos,
                Sdpt:this.staff.Sdpt
              }
            }).then(function (res) {
            if(res.data.flag){
              _this1.tableData=res.data.stas;
              _this1.$message('添加成功')
              _this1.dialogVisible=false;
            }  else{
              alert('添加失败');
            }
            })
        }
      }
    }
</script>

<style scoped>
.toolbar{
  margin-top: 10px;
  margin-bottom: 10px;
}
/*工具栏里面的按钮*/
  .toolbar .el-button{
    margin-right: 10px;
  }
</style>
